# 闰年平年
def isLeapYear(year):
  if (year%4 == 0 and year%100 != 0) or year%400 == 0:
    return True
  else:
    return False
# 某年某月有多少天
list31 = [1,3,5,7,8,10,12]
list30 = [4,6,9,11]
def monthDay(year,month):
  if month in list31:
    return 31
  elif month in list30:
    return 30
  elif month == 2:
    if isLeapYear(year):
      return 29
    else:
      return 28

# 某年有多少天
def yearDay(year):
  return 365 + isLeapYear(year)

# 年份到1900年的总天数
def allYearDay(year):
  return sum([yearDay(i) for i in range(1900,year)])

# 某年某月某日到当年1月1日的天数
def allMonthDay(year,month):
  return sum([monthDay(year,i) for i in range(1,month)])
# 某年某月到1900年1月1日的天数
def ymallDay(year,month):
  return allYearDay(year) + allMonthDay(year,month)
# 某年某月的第一天是星期几,当月有多少天
def weekNum(year,month):
  return (ymallDay(year,month) + 7)%7,monthDay(year,month)

def getCalendar():
  year = int(input("请输入年份："))
  month = int(input("请输入月份："))
  week,day = weekNum(year,month)
  for i in ["星期一","星期二","星期三","星期四","星期五","星期六","星期天"]:
    print(i,end="\t")
  print()
  for i in range(week):
    print("\t",end = "")
  for d in range(1,day+1):
    print(d,end="\t")
    if (week+d)%7==0:
      print()
getCalendar()